//===============================================================================
// Microsoft patterns & practices
// Mobile Client Software Factory - July 2006
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Practices.ObjectBuilder.ObGen
{
	public class NamingContext
	{
		const string varName = "var";
		const string memberName = "Member";
		int autoVarCount = 0;
		int autoMemberCount = 0;

		Dictionary<string, int> namedVars = new Dictionary<string, int>();
		Dictionary<string, int> namedMembers = new Dictionary<string, int>();

		public string GetVariableName()
		{
			return varName + (++autoVarCount);
		}

		public string GetVariableName(string baseName)
		{
			if (!namedVars.ContainsKey(baseName))
			{
				namedVars.Add(baseName, 0);
				return baseName;
			}
			else
			{
				int newIndex = ++namedVars[baseName];
				namedVars[baseName] = newIndex;
				return baseName + newIndex;
			}
		}

		public string GetMemberName()
		{
			return memberName + (++autoMemberCount);
		}

		public string GetMemberName(string baseName)
		{
			if (!namedMembers.ContainsKey(baseName))
			{
				namedMembers.Add(baseName, 0);
				return baseName;
			}
			else
			{
				int newIndex = ++namedMembers[baseName];
				namedMembers[baseName] = newIndex;
				return memberName + newIndex;
			}
		}

	}
}
